package com.njit.farm.service.impl;

import com.njit.farm.dao.FIntegralMapper;
import com.njit.farm.dataobject.FIntegral;
import com.njit.farm.model.Integral;
import com.njit.farm.model.Result;
import com.njit.farm.service.IntegralService;
import com.njit.farm.util.IDUtils;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import javax.print.attribute.standard.Finishings;
import java.util.ArrayList;
import java.util.List;


@Service
public class IntegralServiceImpl implements IntegralService {

    @Resource
    FIntegralMapper integralMapper;

    @Override
    public Result add(Integral integral) {

        Result result = new Result();

        FIntegral fIntegral = new FIntegral();
        fIntegral.setiId(IDUtils.uuid());
        fIntegral.setuId(integral.getuId());
        fIntegral.setiChange(integral.getChange());
        fIntegral.setiRemark(integral.getRemark());

        integralMapper.insert(fIntegral);

        result.setSucc(true);

        return result;
    }

    @Override
    public Result queryByUserId(String uid) {

        Result result = new Result();

        List<FIntegral> fIntegrals = integralMapper.selectByUserId(uid);

        List<Integral> integralList = new ArrayList<>();
        for (FIntegral fIntegral : fIntegrals) {
            Integral integral = fIntegral.toModel();
            integralList.add(integral);
        }

        result.setSucc(true);
        result.setData(integralList);

        return result;
    }
}
